import $http from '../../../servers/http';
import { Result } from 'seats/schema/Result';
import {
  CallrecordsReportRequest,
  CallrecordsReportResponse,
} from 'admin/schema/CallRecordsReport';

/**查询通话记录列表(全部任务报表) */
export const getCallRecordsReportList = (
  data: CallrecordsReportRequest
): Promise<Result<CallrecordsReportResponse[]>> => {
  // get请求，需要转换呼叫结果数组
  let callStatusStr = '';
  let transferManualStatusStr = '';
  data.callStatus?.forEach(status => {
    callStatusStr += `callStatus=${status}&`;
  });
  data.transferManualStatus?.forEach(status => {
    transferManualStatusStr += `transferManualStatus=${status}&`;
  });
  delete data.callStatus;
  delete data.transferManualStatus;
  return $http.get({
    url: `/icms/taskmanage/callrecords?${callStatusStr}${transferManualStatusStr}`,
    data,
  });
};

/**创建下载任务-通话记录报表-导出 */
export const createCallRecordDownloadTask = (
  data: CallrecordsReportRequest
): Promise<Result<null>> => {
  return $http.post({
    url: '/icms/taskmanage/callrecords/export',
    data,
  });
};

/**
 * 查询通话记录中的电话号码是否已经加入黑名单
 */
export const queryPhoneInBlack = (data: {
  callRecordId: string;
}): Promise<
  Result<{
    isBlacklist: boolean;
  }>
> => {
  return $http.post({
    url: '/icms/blacklistmanage/blacklists/isblacklist',
    data,
  });
};

/**
 * 查询全部历史会话记录，修复会话记录不全的问题（新）
 * @param callRecordId
 * @returns
 */
export const refreshHistoryRecords = (callRecordId: any) => {
  return $http.get({
    url: `/icms/taskmanage/callrecords/${callRecordId}/refreshAiCallDialogues`,
  });
};

/**
 * 加入黑名单
 */
export const addPhoneInBlack = (data: { callRecordId: string }): Promise<Result<null>> => {
  return $http.post({
    url: '/icms/blacklistmanage/blacklist',
    data,
  });
};

/**
 * 移出黑名单
 */
export const removePhoneInBlack = (data: { callRecordId: string }): Promise<Result<null>> => {
  return $http.delete({
    url: '/icms/blacklistmanage/blacklist',
    data,
  });
};
